/**
 * 
 */
package pingu.monde;

import java.io.Serializable;

/**
 * @author Cl�ment Nicolas
 *
 */
public class Case implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4631598764787022584L;
	private int nbPoissons;
	private boolean pasFondue=true;
	private Pingouin monPingouin;
	private Plateau monMonde;
	private int x,y;
	private boolean selection;

	public Case(Plateau plateau,int x,int y){
		monMonde=plateau;
		int rand=(int) Math.ceil(Math.random()*100);
		int nbPoissRandom=1;
		if (rand<55) nbPoissRandom=1;
		else if (rand<85)nbPoissRandom=2;
		else if (rand<100)nbPoissRandom=3;
		
		initialiser(nbPoissRandom,x,y);
	}

	public Case(int nbPoiss,Plateau plateau,int x,int y){
		monMonde=plateau;
		initialiser(nbPoiss, x, y);
	}

	public void initialiser(int nbPoissons, int x, int y) {
		this.nbPoissons=nbPoissons;
		this.x=x;
		this.y=y;
	}


	/**
	 *  getters and setters
	 */
	public int getNbPoissons() {
		return nbPoissons;
	}
	public void setNbPoissons(int nbPoissons) {
		this.nbPoissons = nbPoissons;
	}
	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public boolean isPasFondue() {
		return pasFondue;
	}
	public void setPasFondue(boolean pasFondue) {
		this.pasFondue = pasFondue;
	}
	
	public void setSelection(boolean selection) {
		this.selection=selection;		
	}
	
	public boolean getSelection() {
		return selection;		
	}
	
	public Pingouin getMonPingouin() {
		return monPingouin;
	}

	public void setMonPingouin(Pingouin pingouin) {
		monPingouin=pingouin;
		pingouin.privateSetCase(this);
	}
	public void privateSetMonPingouin(Pingouin monPingouin) {
		this.monPingouin = monPingouin;
	}
	public void deletePingouin() {
		if(monPingouin==null)return;
		monPingouin.privateDeleteCase();
		monPingouin=null;
	}

	public void privateDeletePingouin() {
		this.monPingouin = null;
	}

	public boolean estLibre() {
		return monPingouin==null&&pasFondue;
	}

	public boolean estAtteignableDepuis(Case autreCase) {
		return monMonde.casesAtteignablesEnPingouin(autreCase,this);
	}

	public String toString(){
		String s;
		if (pasFondue&&monPingouin!=null) {
			s="I"+nbPoissons+" ";
		}
		else if (pasFondue) {
			s=" "+nbPoissons+" ";
		}
		else{
			s=" . ";
		}
		return s;
	}
}
